package cn.edu.hqu.cst.crj.layoutdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;

import java.util.Timer;
import java.util.TimerTask;

public class Frame extends AppCompatActivity implements View.OnClickListener {
    int[] imgIds = new int[]{R.drawable.p50,R.drawable.p100,
            R.drawable.p150,R.drawable.p200,R.drawable.p250};
    int imgStart =0;
    ImageView imageView;
    Handler handler = new Handler() {
        //重写handleMessage方法，根据msg中what的值判断是否执行后续操作
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                imageView.setImageResource(imgIds[imgStart++ % 5]);
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame);
        //返回
        findViewById(R.id.btn_back).setOnClickListener(this);

        imageView = findViewById(R.id.imageView);
        //使用定时器
        Timer timer =new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                handler.sendEmptyMessage(1);
            }
        }, 0,500);
    }

    @Override
    public void onClick(View v) {
        if(v.getId()==R.id.btn_back)
            finish();
        //startActivity(intent);

    }

}
